//
//  WPOrderViewModel.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/14.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPOrderViewModel.h"
#import "WPOrderModel.h"


@implementation WPOrderViewModel
+ (void)getSuccessOrdertWithPageNumber:(NSInteger)page andWithSuccessBlock:(void (^)(NSArray *, NSInteger))succ andWithFailureBlock:(void (^)(NSString *))fail{
    NSDictionary * params = @{@"pageNumber":@(page),
                              @"pageSize":@(10),
                              @"memberid":[UserModel defaultUser].userID};
    [NetWorkingManager postWithUrl:@"commoditytrade/searchOrderList.jhtml" requestParams:[NetWorkingManager paramsByAppendingUserInfo:params] SuccessHandler:^(id responseObject) {
        if (responseObject[@"resultType"] && [responseObject[@"resultType"] intValue]) {
            NSMutableArray * resultArr = [NSMutableArray array];
            for (NSDictionary * dic in responseObject[@"resultMsg"]) {
                WPOrderModel * model = [WPOrderModel new];
                [model setValuesForKeysWithDictionary:dic];
                [resultArr addObject:model];
            }
            succ(resultArr, responseObject[@"totalpages"] ? [responseObject[@"totalpages"] integerValue]:1);
        } else {
            fail(responseObject[@"resultMsg"]?responseObject[@"resultMsg"]:@"暂无数据");
        }
    } failureHandler:^(NSError *error) {
        fail(error.localizedDescription);
    }];
    
}
@end
